package org.dialMsg.Server.ServerImp;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.mjoys.report.common.pojo.dim.DimDataBatchSyncRequest;
import com.mjoys.report.starter.api.DimSyncApi;
import feign.Request;
import org.dialMsg.Mapper.DimSyncMapper;
import org.dialMsg.Mapper.TDataSourceBatchMapper;
import org.dialMsg.Pojo.TDataSourceBatch;
import org.dialMsg.Pojo.TDialResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class DimEquipSyncRequestServerImp{
    @Autowired
    private DimSyncApi dimSyncApi;


    public void sendDimEquipSyncRequest(List<TDialResult> tDialResults) {
        DimDataBatchSyncRequest dimEquipSyncRequest = new DimDataBatchSyncRequest();
        TDataSourceBatch tDataSourceBatch = new TDataSourceBatch();
        tDialResults.forEach(tDialResult -> {
            dimEquipSyncRequest.setBatchId(Long.valueOf(tDialResult.getDataSourceBatchId()));
            dimEquipSyncRequest.setBatchName(tDialResult.getShowName());
            dimEquipSyncRequest.setSceneId(tDataSourceBatch.getBusinessId());
            dimEquipSyncRequest.setTenantId(tDataSourceBatch.getCompanyUserId());
            dimEquipSyncRequest.setBatchUploadUserId(tDataSourceBatch.getUploadUserId());
            dimEquipSyncRequest.setBatchTotalCount(tDataSourceBatch.getUploadNum());
            dimEquipSyncRequest.setBatchType(0);
            dimEquipSyncRequest.setUploadTime(LocalDateTimeUtil.of(tDataSourceBatch.getUploadDealTime()));
            Request.Options options = new Request.Options( 10L, TimeUnit.SECONDS, 60L, TimeUnit.SECONDS, true);
            dimSyncApi.sync(dimEquipSyncRequest,  options);
        });
    }

//    public void insertDimDataBatch(Integer size) {
//        List<TDataSourceBatch> tDataSourceBatches = dataSourceBatchMapper.queryBySize(size);
//        tDataSourceBatches.forEach(tDataSourceBatch -> {
//            dimSyncMapper.insertBatchSize(tDataSourceBatch.getId(),
//                    tDataSourceBatch.getShowName(),
//                    tDataSourceBatch.getBusinessId(),
//                    tDataSourceBatch.getCompanyUserId(),
//                    tDataSourceBatch.getUploadUserId(),
//                    tDataSourceBatch.getUploadNum(),
//                    tDataSourceBatch.getUploadDealTime());
//        });
//
//
//    }

}